package com.dt76.smallloanbackendservice.controller.lhuaw;


import com.dt76.smallloanbackendservice.pojo.lhuaw.SystemMessage;
import com.dt76.smallloanbackendservice.service.lhuaw.SystemMessageService;
import com.dt76.smallloanbackendservice.utils.Page;
import com.dt76.smallloanbackendservice.utils.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;


@Controller
@RequestMapping("/lhuaw")
public class SystemMessageController {
    @Resource
    private SystemMessageService systemMessageService;

    @RequestMapping("/getAll")
    @ResponseBody
    public List<SystemMessage> SystemMessage1(){
        return systemMessageService.getAll();
    }
//@RequestMapping("/getAll")
//public List<SystemMessage> SystemMessage1() {
//    return systemMessageService.getAll();
//}
//    @RequestMapping("/getAll")
//    public String SystemMessage1(Model model){
//        model.addAttribute("getAll",systemMessageService.getAll());
//        return "pages/lhuaw/SystemMessage";
//    }
    @RequestMapping("/qryConditionPageAll")
    @ResponseBody
    public Page qryConditionPageAll(@RequestParam("pageIndex")  int pageIndex,
                                    @RequestParam("messageTitle") String messageTitle,
                                    @RequestParam("publisher") String publisher){
        System.out.println("成功调用远程");
        return systemMessageService.getAllSystemMessage(pageIndex, messageTitle, publisher);
    }
//删除
    @RequestMapping("/delSystem")
    @ResponseBody
    public Result delSystem(@RequestParam("sId")int sId){
        System.out.println("成功调用删除方法，正在执行SystemMessageController.delSystem>>>>>>>>");
        try {
            systemMessageService.deleteSystem(sId);
            return new Result(true,"删除成功>>>");
        } catch (Exception e) {
            return new Result(false,"删除失败>>>");
        }
    }
 //新增
 @RequestMapping("/addSystem")
 @ResponseBody
 public Result addSystem(@RequestBody SystemMessage systemMessage){
     System.out.println("成功调用远程服务:systemMessageService>addSystem>>>");
     //调用新增接口
     try {
             systemMessageService.addSystem(systemMessage);
             return new Result(true,"新增成功>>>");
     } catch (Exception e) {
         return new Result(false,"新增失败>>>");
     }
 }
 //查看
    @RequestMapping("/seeSystem")
    @ResponseBody
    public SystemMessage seeSystem(@RequestParam("sId") int sId){
        System.out.println("成功调用远程服务:systemMessageService>getAllSystemId>>>");
        return systemMessageService.seeSystem(sId);
    }
}
